import { bindable, containerless } from 'aurelia-framework';

@containerless
export class EmProjectModal {

    @bindable value;

    valueChanged(newValue, oldValue) {

    }

    /**
     * 构造函数
     */
    constructor() {
        this.subscribe = ea.subscribe(nsCons.EVENT_TASK_PROJECT_CREATED, (payload) => {
            this.projects.push(payload.project);
        });
    }

    /**
     * 当数据绑定引擎从视图解除绑定时被调用
     */
    unbind() {
        this.subscribe.dispose();
    }

    _listProjects() {
        $.get('/admin/task/project/listMy', (data) => {
            if (data.success) {
                this.projects = data.data;
            } else {
                toastr.error(data.data);
            }
        });
    }

    show() {
        this.emModal.show();
    }

    showHandler() {
        this._listProjects();
    }

    approveHandler() {

    }
    createHandler() {
        this.projectCreateVm.show();
    }
    editHandler(item) {
        this.projectEditVm.show({
            project: item
        });
    }
}
